package org.summer.lawyer.controller.admin;

import cn.dev33.satoken.annotation.SaIgnore;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.summer.common.core.domain.R;
import org.summer.common.mail.utils.MailUtils;
import org.summer.lawyer.mail.SendMailTestService;
import org.summer.lawyer.service.IMailLogService;

import java.io.File;

@Tag(name = "后台相关接口",description = "邮件发送测试")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mail")
public class MailController {


    private final SendMailTestService sendMailTestService;

    private final IMailLogService mailLogService;
    /**
     * 发送邮件
     *
     * @param to      接收人
     * @param subject 标题
     * @param text    内容
     */
    @SaIgnore
    @GetMapping("/sendSimpleMessage")
    public R<Void> sendSimpleMessage(String to, String subject, String text) {
        MailUtils.sendText(to, subject, text);
        sendMailTestService.sendMail();
        return R.ok();
    }

    /**
     * 发送邮件（带附件）
     *
     * @param to       接收人
     * @param subject  标题
     * @param text     内容
     * @param filePath 附件路径
     */
    @SaIgnore
    @GetMapping("/sendMessageWithAttachment")
    public R<Void> sendMessageWithAttachment(String to, String subject, String text, String filePath) {
        MailUtils.sendText(to, subject, text, new File(filePath));
        return R.ok();
    }
}
